package com.jyc.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.jyc.entity.shop.Item;
import com.jyc.service.ShopService;
import com.jyc.util.HttpResult;
import com.jyc.vo.ck.ShebeiguihaiVO;
import com.jyc.vo.shop.ItemChartVO;
import com.jyc.vo.shop.ItemVO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

@RestController
@CrossOrigin("*")
@RequestMapping("/shop")
public class ShopController {
    @Autowired
    private ShopService shopService;

    /**
     * 商品信息
     * @return
     */
    @RequestMapping("/toList")
    public HttpResult toList(@RequestParam("pageIndex") Integer pageIndex, @RequestParam("pageSize") Integer pageSize) {
        PageHelper.startPage(pageIndex,pageSize);
        List<Item> items = shopService.getItemList();
        List<ItemVO> itemVOS = new ArrayList<>();
        for (Item item: items) {
            ItemVO itemVO = new ItemVO();
            BeanUtils.copyProperties(item,itemVO);
            itemVOS.add(itemVO);
        }
        PageInfo<Item> pageInfo = new PageInfo<Item>(items, pageSize);
        return HttpResult.ok(pageInfo);
    }

    /**
     * 售出商品的分类占比
     * @return
     */
    @RequestMapping("/showPie")
    public HttpResult showPie() {
        List<ItemChartVO> zucheChartVOS = shopService.showPie();
        return HttpResult.ok(zucheChartVOS);
    }

    /**
     * 不同商品分类的购买量
     * @return
     */
    @RequestMapping("/showPillar")
    public HttpResult showPillar() {
        List<ItemChartVO> zucheChartVOS = shopService.showPillar();
        return HttpResult.ok(zucheChartVOS);
    }

    /**
     * 不同商品分类的售出总价
     * @return
     */
    @RequestMapping("/showLine")
    public HttpResult showLine() {
        List<ItemChartVO> zucheChartVOS = shopService.showLine();
        return HttpResult.ok(zucheChartVOS);
    }

    /**
     * 不同时间的不同商品分类的总购买量
     * @return
     */
    @RequestMapping("/show3DByNum")
    public HttpResult show3DByNum() {
        Set<List> chartVOS = shopService.show3DByNum();
        return HttpResult.ok(chartVOS);
    }

    /**
     * 不同时间的不同商品分类的交易总额
     * @return
     */
    @RequestMapping("/show3DByPrice")
    public HttpResult show3DByPrice() {
        Set<List> chartVOS = shopService.show3DByPrice();
        return HttpResult.ok(chartVOS);
    }
}
